package com.my.android;


import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

class BindData {
    String title;
    String line1;
    String line2;

    public BindData(String string0, String string1, String string2) {
        this.title = string0;
        this.line1 = string1;
        this.line2 = string2;
    }
}

class ViewHolder {
    TextView title;
    TextView line1;
    TextView line2;
}

public class MyAdapter extends ArrayAdapter<BindData> {

    private LayoutInflater inflater;

    public MyAdapter(Context context, List<BindData> objects) {
        super(context, 0, objects);
        this.inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public boolean isEnabled(int position) {
        // 選択不可にする
        return true;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.raw, parent, false);
            holder = new ViewHolder();
            holder.title = (TextView) convertView.findViewById(R.id.title);
            holder.line1 = (TextView) convertView.findViewById(R.id.line1);
            holder.line2 = (TextView) convertView.findViewById(R.id.line2);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        BindData data = getItem(position);

        //Log.d("タグ", ":" + position);
        //Log.d("タグ", "::" + data.title);
        //Log.d("タグ", ":::" + isEnabled(position));

        // タイトル
        if ( getItem(position).title != null ) {
            holder.title.setVisibility(View.VISIBLE);
            holder.title.setText(data.title);
            holder.line1.setVisibility(View.GONE);
            holder.line2.setVisibility(View.GONE);
        // line1,2
        } else {
            holder.title.setVisibility(View.GONE);
            holder.line1.setVisibility(View.VISIBLE);
            holder.line1.setText(data.line1);
            holder.line2.setVisibility(View.VISIBLE);
            holder.line2.setText(data.line2);
        }
        return convertView;
    }
}